﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Configuration;
using BesAsm.MasterData.Data;
using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Services;
using BesAsm.MasterData.Data.Bases;
using BesAsm.MasterData.Data.SqlClient;

namespace BesAsm.MasterData.Gis
{
  /// <summary>
  /// Provides master data access and services
  /// </summary>
  public static class ProviderInitializer
  {
    /// <summary>
    /// Sets up the master data provider
    /// </summary>
    /// <param name="connectionString">Connection string to sql server containing master data</param>
    public static void InitializeProvider(string connectionString)
    {
      NetTiersProvider provider = new SqlNetTiersProvider();
      NameValueCollection config = new NameValueCollection();
      config.Add("useStoredProcedure", "false");
      config.Add("connectionString", connectionString);
      config.Add("connectionStringName", "netTiersConnectionString");
      config.Add("providerInvariantName", "System.Data.SqlClient");
      config.Add("useEntityFactory", "true");
      config.Add("enableEntityTracking", "false");
      config.Add("enableMethodAuthorization", "false");  
      config.Add("defaultCommandTimeout", "120");

      provider.Initialize("SqlNetTiersProvider", config);      
      DataRepository.LoadProvider(provider, true);
    }
  }
}
